package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.model.po.SysCompanyPO;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import javax.xml.parsers.SAXParser;
import java.util.Map;

/**
 * <p>todo 公司维护provider</p>
 * @author: WCZ
 * @created: 2022/6/22$ 9:54$
 * @version v1.0.1
 */

public class SysCompanySqlProvider implements ProviderMethodResolver {
  /**
   * <p>todo 公司维护列表分页查询</p >
   * @param page 分页
   * @param qc  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/5 9:23
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/5 wcz v1.0.1 init
   */
  public static String findCompanies(Page<Map<String, Object>> page, String qc) {
    StringBuffer companySql = new StringBuffer();
    companySql.append("select id ,\n");
    companySql.append("code, \n");
    companySql.append("cname, \n");
    companySql.append("sname, \n");
    companySql.append("address, \n");
    companySql.append("contact, \n");
    companySql.append("legal_person legalPerson, \n");
    companySql.append("type, \n");
    companySql.append("kind, \n");
    companySql.append("biz_type, \n");
    companySql.append("status \n");
    companySql.append("from sys_company \n");
    companySql.append("where ");
    companySql.append(qc);
    companySql.append("  and del_flag = 0");
    return companySql.toString();
  }

  /**
   * <p>todo 新增重名校验</p >
   * @param sysCompanyPO  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/5 9:24
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/5 wcz v1.0.1 init
   */
  public String checkCompany(SysCompanyPO sysCompanyPO) {
    StringBuffer companySql = new StringBuffer();
    companySql.append("select count(1) \n");
    companySql.append("from sys_company \n");
    companySql.append(" WHERE CODE = '" + sysCompanyPO.getCode() + "'  or \n");
    companySql.append(" cname = '" + sysCompanyPO.getCname() + "' or \n");
    companySql.append(" sname = '" + sysCompanyPO.getSname() + "'  \n");
    return companySql.toString();
  }
  /***
   * <p>todo 公司维护导出</p >
   * @param fields 导出字段
   * @param qc  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/5 9:25
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/5 wcz v1.0.1 init
   */
  public String exportCompanies(String fields, String qc)
  {
    StringBuffer sql = new StringBuffer();
    sql.append("select ");
    sql.append(fields);
    sql.append(" from sys_company \n");
    sql.append("where ");
    sql.append(qc);
    sql.append("  and del_flag = 0");
    sql.append(" order by code asc \n");
    return sql.toString();
  }

  /**
   * <p>todo 根据id查询</p >
   * @param id  * @return : java.lang.String
   * @author: wcz
   * @date: 2022/7/5 9:26
   * @version: 1.0.1
   * Modification History:
   * Date Author Version Description
   * -----------------------------------------------------------
   * 2022/7/5 wcz v1.0.1 init
   */
  public String findCid(long id)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	count(*) \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_dept d \n ");
    sql.append(" where\n ");
    sql.append(" 	d.company_id =  \n ");
    sql.append(id);
    sql.append(" 	and d.`status` = 100201\n ");

    return sql.toString();
  }
}
